from django.shortcuts import render
from django.views import View

from courses.models import Course, BannerCourse
from organization.models import CourseOrg
from users.models import Banner


class IndexView(View):
    def get(self, request):
        all_banners = [banner for banner in Banner.objects.order_by('index')[:5]]
        courses = [course for course in Course.objects.order_by('-click_nums')[:6]]
        banner_courses = [bannercourse for bannercourse in BannerCourse.objects.filter(is_banner=True).order_by('-click_nums')[:5]]
        course_orgs = [courseorg for courseorg in CourseOrg.objects.order_by('-click_nums')[:15]]
        return render(request, 'index.html', {
            'all_banners': all_banners,
            'courses': courses,
            'banner_courses': banner_courses,
            'course_orgs': course_orgs,
        })
    # all_banners 获取轮播图表(Banner)所有轮播图数据
    # courses  获取课程信息表(Course)中的课程信息数据
    # banner_courses 获取课程信息表中(Course)的课程信息数据 和上面数据一样
    # course_orgs  获取课程学校表(CourseOrg)中的数据
